package com.ziyun.erp.web.modules.systemVersion.controller;

import java.util.Arrays;
import java.util.Map;

import com.service.cache.constants.CachePrefix;
import com.service.cache.constants.RegionPrefix;
import com.service.cache.core.CacheService;
import com.utility.StringTool;
import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ziyun.erp.modules.systemVersion.entity.SystemVersionEntity;
import com.ziyun.erp.modules.systemVersion.service.SystemVersionService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 版本表
 *
 * @author jiangli
 * @email 
 * @date 2018-10-30 13:40:09
 */
@RestController
@RequestMapping("systemVersion/systemversion")
public class SystemVersionController {
    @Autowired
    private SystemVersionService systemVersionService;
    @Autowired
    private CacheService cacheService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("systemVersion:systemversion:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = systemVersionService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("systemVersion:systemversion:info")
    public R info(@PathVariable("id") Integer id){
        SystemVersionEntity systemVersion = systemVersionService.selectById(id);

        return R.ok().put("systemVersion", systemVersion);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("systemVersion:systemversion:save")
    public R save(@RequestBody SystemVersionEntity systemVersion){
        systemVersionService.insert(systemVersion);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("systemVersion:systemversion:update")
    public R update(@RequestBody SystemVersionEntity systemVersion){
        ValidatorUtils.validateEntity(systemVersion);
        systemVersionService.updateAllColumnById(systemVersion);//全部更新
        cacheService.removeFromCache(CachePrefix.systemVersionsAndroid, RegionPrefix.one_day);
        cacheService.removeFromCache(CachePrefix.systemVersionsIos, RegionPrefix.one_day);
        cacheService.removeFromCache(CachePrefix.systemVersionsTuwenBaoAndroid, RegionPrefix.one_day);
        cacheService.removeFromCache(CachePrefix.systemVersionsTuwenBaoIos, RegionPrefix.one_day);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("systemVersion:systemversion:delete")
    public R delete(@RequestBody Integer[] ids){
        systemVersionService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
